package com.basic;

public class Individual {
	protected Market market;
	protected Double wealth;
	
	protected Individual(Market market, double wealth){
		this.market = market;
		this.wealth = wealth;
	}
	
	public void purchase(int n){
		System.out.println("purchase");
		this.market.sellGood(n);
	}
	/**Purchases a good by the given cost or the 
	 * next least cost (but never higher).  ie if cost = 3.0
	 * and the arraylist contains 2.8 and 3.1, the 2.8 will
	 * be purchased.
	 * */
	public void purchaseByCost(double cost){
		
		MarketHelper mh = this.market.sellGoodByCost(cost);
		System.out.println("the loc is: " + mh.location);
		if(mh.cost < this.wealth && mh.location != -1){
			System.out.println("deduct: " + mh.cost);
			this.wealth = this.wealth - mh.cost;
			this.market.removeGood(mh.location);
		}else{
			System.out.println("you can't afford that. Or it doesn't exist.");
		}
			
			
		
	}
	
	public void sell(){
		System.out.println("sell");
	}
	
	public void consume(){
		System.out.println("consume");
	}
}
